﻿using System;
using Microsoft.Devices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Media;

namespace Groovy_IM.Assets
{
    public class Actions
    {
        public delegate void AddAccount2(int Account);

        public event AddAccount2 AddAccounts;

        public void AddAccount(int Protocol, string Screenname, string Password, string Server, int Port, string Description, bool AutoLogin, bool MobileLogin, bool InvisLogin, bool SaveLogin)
        {
            Uri m_Icon = new Uri("Images/Protocols/AIM.png", UriKind.Relative);

            switch (Protocol)
            {
                case 0:
                    m_Icon = new Uri("Images/Protocols/AIM.png", UriKind.Relative);
                    break;
            }

            App.Accounts.Items.Add(new ViewModels.Accounts.AccountItemViewModel() { Password = Password, Username = Screenname, SignedOn = false, Protocol = Protocol, pProtocol = m_Icon, Tag = App.Accounts.Items.Count.ToString(), pSelected = 0, Selected = new Uri("Images/Protocols/nonselected.png", UriKind.Relative), Server = Server, Port = Port, Description = Description, AutoLogin = AutoLogin, InvisibileLogin = InvisLogin, MobileLogin = MobileLogin, SaveDetails = SaveLogin });

            if (AddAccounts != null)
                AddAccounts(App.Accounts.Items.Count);
        }

        public void CloseChat(int Account, int Chat)
        {

        }

        public void JoinChat(int Account, string Room, string Exchange, string RoomType, string Instance, string Details)
        {
            if (Room.Length < 1)
                return;

            App.m_Proto[Account].JoinChat(Room, Exchange, RoomType, Instance, Details);
        }

        public void RequestInvite(int Account, int Chat, string Buddy, string InviteMessage)
        {
            if (Buddy.Length < 1)
                return;

            App.m_Proto[Account].InviteFriend(Chat, Buddy, InviteMessage);
        }

        public void RequestProfile(int Account, string Buddy)
        {
            if (Buddy.Length < 1)
                return;

            App.m_Proto[Account].GrabUserInfo(Buddy);
        }

        public void SendChat(int Account, int Chat, string Message)
        {
            if (Message.Length < 1)
                return;

            App.m_Proto[Account].SendChatMessage(Chat, Message);
        }

        public void Vibrate(int ms)
        {
            VibrateController vc = VibrateController.Default;
            vc.Start(TimeSpan.FromMilliseconds(ms));
        }

        /*Other Functions*/
        private int mLastColor;

        private Color[] mColors = { Colors.Brown, Colors.Green, Colors.Magenta, Colors.Orange, Colors.Purple, Colors.Red };

        public Color GetNextColor()
        {
            if (mLastColor >= mColors.Length) mLastColor = 0;
            return mColors[mLastColor++];
        }

        public string StripHTML(string Text)
        {
            return Regex.Replace(Text, @"<(.|\n)*?>", string.Empty);
        }
    }
}
